home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Unix / satan-1.1.1 / perl / trust.pl < prev   
Text File  |  1995-04-10  |  3KB  |  131 lines

  1. #
  2. # update_trust - maintain trust statistics
  3. #
  4. # Output to: 
  5. #
  6. # $total_trusted_count{host} number of non-ANY trust relationships
  7. # $total_trusted_names{host} names of trusted hosts
  8. #
  9. # $total_trustee_count{host} number of non-ANY trust relationships
  10. # $total_trustee_names{host} names of trustee hosts
  11. #
  12. # $trust_host_type{trusted trustee}{type} all facts about this relationship.
  13. # $trust_type_host{type}{trusted trustee} all facts about this relationship.
  14.  
  15. $trust_files = "rules/trust";
  16. $trust_other = "other";
  17.  
  18. sub build_update_trust {
  19.     local($files) = @_;
  20.     local($code, $type);
  21.  
  22.     $code = '
  23. sub update_trust {
  24.     local($td_host, $te_host);
  25.     ($td_host = $trusted) =~ s/(.*@)?(.*)/$2/;
  26.     ($te_host = $trustee) =~ s/(.*@)?(.*)/$2/;
  27.  
  28.     return 
  29.     if $td_host eq "" || $te_host eq ""
  30.     || $td_host eq "ANY" || $td_host eq $te_host;
  31.  
  32.     if (!exists($trust_host_type{"$td_host $te_host"})) {
  33.     $total_trustee_names{$td_host} .= "$te_host ";
  34.     $total_trustee_count{$td_host}++;
  35.     $total_trusted_names{$te_host} .= "$td_host ";
  36.     $total_trusted_count{$te_host}++;
  37.     }
  38. ';
  39.  
  40.     foreach $file (split(/\s+/, $files)) {
  41.     open(RULES, $file) || die "cannot open $file: $!";
  42.     while (<RULES>) {
  43.         chop;
  44.         while (/\\$/) {
  45.         chop;
  46.         $_ .= <RULES>;
  47.         chop;
  48.         }
  49.         s/#.*$//;
  50.         s/\s+$//;
  51.         next if /^$/;
  52.         s/@/\\@/g;
  53.         ($cond, $type) = split(/\t+/, $_, 2);
  54.         die "missing trust type" if $type eq "";
  55.         $code .= "\
  56.     if ($cond) {
  57.     \$trust_host_type{\"\$td_host \$te_host\"}{\"$type\"} .= \$_ . \"\\n\";
  58.     \$trust_type_host{\"$type\"}{\"\$td_host \$te_host\"} .= \$_ . \"\\n\";
  59.     return;
  60.     }\
  61. ";
  62.     }
  63.     close(RULES);
  64.     }
  65.     $code .= "\
  66.     \$trust_host_type{\"\$trustee \$trusted\"}{\"other\"} .= \$_ . \"\\n\";
  67.     \$trust_type_host{\"other\"}{\"\$trustee \$trusted\"} .= \$_ . \"\\n\";
  68. }\n";
  69.     return $code;
  70. }
  71.  
  72. #
  73. # Reset all trust information tables.
  74. #
  75. sub clear_trust_info {
  76.     %total_trust_pair = ();
  77.     %total_trustee_names = ();
  78.     %total_trustee_count = ();
  79.     %total_trusted_names = ();
  80.     %total_trusted_count = ();
  81.     %trust_host_type = ();
  82. }
  83.  
  84. #
  85. # Some scaffolding for stand-alone operation
  86. #
  87. if ($running_under_satan) {
  88.     eval &build_update_trust($trust_files);
  89.     die "error in $trust_files: $@" if $@;
  90. } else {
  91.     $running_under_satan = -1;
  92.     $debug = 1;
  93.  
  94.     require 'perl/misc.pl';
  95.  
  96.     #
  97.     # Generate code from rules files.
  98.     #
  99.     $code = &build_update_trust($trust_files);
  100.     print "Code generated from $trust_files:\n\n";
  101.     print $code;
  102.     eval $code; 
  103.     die "error in $trust_files: $@" if $@;
  104.  
  105.     #
  106.     # Apply rules.
  107.     #
  108.     print "\nApplying rules to all SATAN records...\n";
  109.     while (<>) {
  110.         chop;
  111.         if (&satan_split($_) == 0) {
  112.             &update_trust($_);
  113.         }
  114.     }
  115.  
  116.     print "Trusted Trustee Type...\n";
  117.     for $pair (sort keys %trust_host_type) {
  118.     print $pair,' ',sort(join(' ', keys %{$trust_host_type{$pair}})),"\n";
  119.     }
  120.  
  121.     print "\nType Trusted Trustee...\n";
  122.     for $type (sort keys %trust_type_host) {
  123.     for $pair (sort keys %{$trust_type_host{$type}}) {
  124.         print "$type $pair\n";
  125.     }
  126.     }
  127. }
  128.  
  129. 1;
  130.